package com.second.app.thread.join.joinmore;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author GYZ
 * <pre>
 *
 * </pre>
 */
public class AA {

    public static void main(String[] args) throws InterruptedException {

        ReentrantLock reentrantLock = new ReentrantLock();

        Thread b = new Thread(() -> {
            doTest(reentrantLock);
        }, "线程B");

        Thread a = new Thread(() -> {
            synchronized (reentrantLock) {
                try {
                    System.out.println("begin A ThreadName=" + Thread.currentThread().getName() + " " + System.currentTimeMillis());
                    Thread.sleep(5000);
                    System.out.println("end A ThreadName=" + Thread.currentThread().getName() + " " + System.currentTimeMillis());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "线程A");

        a.start();
        b.start();
        b.join(2000);
        System.out.println("         main end " + System.currentTimeMillis());

    }

     private static void doTest( ReentrantLock reentrantLock) {

        synchronized (reentrantLock){
            try {
                System.out.println("begin B ThreadName=" + Thread.currentThread().getName() + " " + System.currentTimeMillis());
                Thread.sleep(5000);
                System.out.println("end B ThreadName=" + Thread.currentThread().getName() + " " + System.currentTimeMillis());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
